﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DatabaseSynchronizer {
    
    public abstract class DBServiceBase {

        protected string ConnectionString;


        protected const string ConnStringTestSQL = "CREATE TABLE TstTabTst([TestCol] int); Insert into TstTabTst values(1); DROP TABLE TstTabTst";
        
        protected const string Sql_Insert_SchemaChange = "INSERT INTO [SchemaChange] ([PatchNumber], [ScriptFile] ,[ExecutionDate] ,[ExecutedBy], [IsLocal]) " +
                                    "VALUES (@PachNum, @ScriptFile ,@ExecutionDate , @ExecutedBy, @IsLocal);";

        protected const string Sql_Select_ExecutePatches = "Select [PatchNumber] from [SchemaChange];";

        protected const string Sql_Select_IsPatchExecuted = "SELECT 1 FROM [dbo].[SchemaChange] WHERE PatchNumber = @PatchNumber;";

        protected const string Sql_SchemaChangeTableExist = "SELECT top 1 1 FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SchemaChange]') AND type in (N'U');";

        protected const string Sql_CreateSchemaChangeTable = "CREATE TABLE [dbo].[SchemaChange]("
                                                            + "	[SchemaChangeId] [int] IDENTITY(1,1) NOT NULL,"
                                                            + "	[PatchNumber] [int] NOT NULL,"
                                                            + "	[ScriptFile] [nvarchar](256) NOT NULL,"
                                                            + "	[ExecutionDate] [datetime] NOT NULL,"
                                                            + "	[ExecutedBy] [nvarchar](50) NOT NULL,"
                                                            + "	[IsLocal] [bit] NOT NULL,"
                                                            + " CONSTRAINT [PK_SchemaChanges] PRIMARY KEY CLUSTERED "
                                                            + "(	[SchemaChangeId] ASC )"
                                                            + "WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, " 
                                                            + "IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]"
                                                            + ") ON [PRIMARY]";

    }
}
